//cache缓存
import Cache from '@/utils/cache.js'
//基础配置
import APP from '@/config/app.js'
//公共方法
import methodBase from '/common/base.js';
//语言
import Lang from '@/utils/lang.js';
//基础
import Base from '@/common/base.js'
//打帮赛方法
import hitmatchcommon from '@/common/hitmatchcommon.js';
//打帮赛方法
import GetUserLib  from '@/lib/eventuserslib.js'


class HitLogin {

	//获取code
	getcode(data = '') {
		return new Promise((resolve, reject) => {
			var that = this;
			uni.login({
				provider: "weixin",
				success: function(res) {
					resolve(res.code);
				},
			});
		});

	}


	/**
	 * 微信登录
	 * 
	 */
	weixinglogin() {
		var that = this;
		uni.login({
			provider: "weixin",
			success: function(res) {
				that.getopenid(res.code);
			}
		});
	}
	/**
	 * 获取openid
	 * 
	 */
	async getopenid(code) {
		var that = this;
		var data = {};
		data['code'] = code;
		var backmsg = await GetUserLib.getOpenidApi(data);
		that.weixingreg(backmsg.data.data);
	}
	/**
		 * 微信注册
		 * 
		 */
		weixingreg(information) {
			//有错误
			if (information.code == '1') {
				//无错误
				Cache.set('user_openid', information.data.openid);
				Cache.set('user_unionid', information.data.unionid);
				//插入或者更新数据
				var data = {};
				var ifreg=0;//是否注册
				if (information.data.openid) {
					data['openid'] = information.data.openid;
					hitmatchcommon.getwxUserLibMethod(data);//授权得到用户
				}
			} else {
				//弹出
				methodBase.publicpopup(Lang.lang.authorisationerror, Lang.lang.authorisationerrordesc);
			}
		}
	 
	 
	}
	


export default new HitLogin;